// pages/packageA//pages/paiShop/storeComment/index.js
// const requestno = require('../../../../utils/request').requestno
// const request = require('../../../../utils/request').request
// const utils = require('../../../../utils/util')
// const config = require('../../../../config.js')
const app = getApp()
const ip=app.globalData.ip
Page({

  /**
   * 页面的初始数据
   */
  data: {
    formList: {
      quality: 4,
      manner: 4,
      fatisfy: 4,
    },
    //imgHost: config.imageHost,

    count: 1,
    showImgUrl: "https://app.flypi.cn", //路径拼接，一般上传返回的都是文件名，
    uploadImgUrl: 'https://app.flypi.cn/adminUser/cache', //图片的上传的路径


    List: [{
        name: '质量评价',
        value: 'quality',
        wordList: ["非常差", "差", "一般", "好", "非常好"]
      },
      {
        name: '态度评价',
        value: 'manner',
        wordList: ["非常差", "差", "一般", "好", "非常好"]
      },
      {
        name: '服务满意度',
        value: 'fatisfy',
        wordList: ["非常差", "差", "一般", "好", "非常好"]
      },
    ],
    initData: [],
    introduce: '',
    caseList: [],
    storeid:'',
    assignmentId:'',
    assignmentDetails:{},
    commentDetails:{}
  },

  rateChange(value) {
    let index = value.currentTarget.id
    switch (index) {
      case '0':
        this.setData({
          'formList.quality': value.detail
        })
        break;
      case '1':
        this.setData({
          'formList.manner': value.detail
        })
        break;
      case '2':
        this.setData({
          'formList.fatisfy': value.detail
        })
        break;
      default:
        break;
    }

  },
  inputMessage(e) {
    console.log(e)
    this.setData({
      introduce: e.detail.value
    })
  },
  sumbit() {
    let self = this
    let quality = self.data.formList
    console.log(quality);
    wx.request({
      url: ip+'/StoreToAssignment/CommentMyOrderToStore',
      data:{
        orderId:this.data.assignmentId,
        score01:quality.quality,
        score02:quality.manner,
        score03:quality.fatisfy,
        content:this.data.introduce
      },
      method:"POST",
      header: {
        "Content-Type": "application/json"
        },
        success:res=>{
          console.log(res)
          wx.showToast({
            title: '操作成功！', // 标题
            icon: 'success',  // 图标类型，默认success
            
            success:res=>{
              let assignmentId=this.data.assignmentId;
              let storeid=this.data.storeid;
              let jsonobj = {"assignmentId":assignmentId,"storeid":storeid};
              this.onLoad(jsonobj)
            }
          })
        }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options)
    let assignmentId = options.assignmentId
    let storeid = options.storeid
    this.setData({
      assignmentId:assignmentId,
      storeid:storeid
    })
    this.selectComment(),
    this.SelectStoreDetail()
  },
  //查询评价
  selectComment(){
    wx.request({
      url: ip+'/StoreToAssignment/selectComment',
      data:{
        assignmentId:this.data.assignmentId,
        storeid:this.data.storeid
      },
      success:res=>{
        console.log(res)
        this.setData({
          commentDetails:res.data.data
        })
        if(this.data.commentDetails!=null){
          this.setData({
            'formList.quality': res.data.data.score01,
            'formList.manner': res.data.data.score02,
            'formList.fatisfy': res.data.data.score03,
            //introduce:res.data.data.content
          })
        }
      }
    })
  },
  //查询小店细节
  SelectStoreDetail(){
    wx.request({
      url: ip+'/StoreToAssignment/selectOrderDetails',
      data:{
        assignmentId:this.data.assignmentId
      },
      success:res=>{
        console.log(res)
        this.setData({
          assignmentDetails:res.data.data
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  collect(){
    console.log(this.data.assignmentDetails.storeId)
    wx.request({
      url: ip+'/store/collect',
      data:{
        storeId:this.data.assignmentDetails.storeId,
        userId:wx.getStorageSync('userid'),
        assignmentId:this.data.assignmentId
      },
      success:res=>{
        console.log(res)
        wx.showToast({
          title: res.data.data,
          success:res=>{
            let assignmentId=this.data.assignmentId;
            let storeid=this.data.storeid;
            let jsonobj = {"assignmentId":assignmentId,"storeid":storeid};
            this.onLoad(jsonobj)
          }
        })
      }
    })
  }
})